package gui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ExpandBar;
import org.eclipse.swt.widgets.ExpandItem;

/**
 * Panel for in the Infobar.
 */
public class InfoPanel extends Composite {
	private ExpandItem item;
	
	/**
	 * Construct a panel in the infobar.
	 * @param infoBar ExpandBar to create the panel in.
	 * @param title Title of the panel.
	 */
	public InfoPanel(ExpandBar infoBar, String title) {
		super(infoBar, SWT.NONE);
		addToInfoBar(infoBar, title);
	}
	
	/**
	 * Add this panel to the infobar.
	 * @param infoBar
	 * @param title
	 */
	private void addToInfoBar(ExpandBar infoBar, String title) {
		item = new ExpandItem(infoBar, SWT.NONE, 0);
		item.setText(title);
		item.setControl(this);
		item.setExpanded(true);
	}
	
	/**
	 * Update the height of the InfoPanel.
	 */
	public void updateHeight() {
		item.setHeight((int) (this.computeSize(SWT.DEFAULT, SWT.DEFAULT).y * 1.2 + 10));
	}
	
	/**
	 * Set whether the InfoPanel must be expanded.
	 * @param expanded
	 */
	protected void setExpanded(boolean expanded) {
		item.setExpanded(expanded);
	}
	
	/**
	 * Set an icon in the top left of the InfoPanel (e.g. SWT.ICON_QUESTION).
	 * @param icon
	 */
	protected void setIcon(int icon) {
		Image image = Display.getCurrent().getSystemImage(icon);		
		item.setImage(image);
	}
}
